package com.fll.fangyishare.service.impl;

import com.fll.fangyicommon.entity.share.Comment;
import com.fll.fangyicommon.entity.share.CommentLiked;
import com.fll.fangyishare.dao.CommentDao;
import com.fll.fangyishare.dao.CommentLikedDao;
import com.fll.fangyishare.service.CommentLikedService;
import com.fll.fangyishare.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @author fll
 * create 2023/3/26
 */
@Service
@Slf4j
public class CommentLikedServiceImpl implements CommentLikedService {

    @Autowired
    private CommentLikedDao commentLikedDao;

    /**
     * 判断当前登录用户是否已点赞某条评论
     * @param userId
     * @param shareId
     * @param commentId
     * @return
     */
    public Boolean isLike(Integer userId, Integer shareId, Integer commentId){
        CommentLiked commentLiked = commentLikedDao.isLike(userId, shareId, commentId);
        if (commentLiked != null){
            return true;
        }
        return false;
    }

    /**
     * 添加一条share评论的点赞记录
     * @param commentLiked
     * @return
     */
    public Integer addCommentLiked(CommentLiked commentLiked){
        Integer num = commentLikedDao.addCommentLiked(commentLiked);
        if (num != 0){
            log.info("share评论点赞成功");
            return num;
        }
        log.warn("share评论点赞失败");
        return -1;
    }

    /**
     * 取消点赞，即删除记录
     * @param commentLiked
     * @return
     */
    public Integer cancelCommentLiked(CommentLiked commentLiked){
        Integer num = commentLikedDao.cancelCommentLiked(commentLiked);
        if (num != 0){
            log.info("share评论的点赞已删除");
            return num;
        }
        log.warn("share评论的点赞删除失败");
        return -1;
    }

    /**
     * 获取share下每条评论的点赞数
     * @param shareId
     * @param commentId
     * @return
     */
    public Integer getCommentLikeCount(Integer shareId, Integer commentId){
        return commentLikedDao.getCommentLikeCount(shareId, commentId);
    }

}
